package com.santu.edu.supporter.biz.user.service.impl;

import com.santu.edu.supporter.biz.user.dao.UserAdressDao;
import com.santu.edu.supporter.biz.user.pojo.dto.UserAddressDTO;
import com.santu.edu.supporter.biz.user.pojo.params.UserAddressAddParam;
import com.santu.edu.supporter.biz.user.pojo.params.UserAddressUpdateParam;
import com.santu.edu.supporter.biz.user.service.UserAdressService;
import com.santu.edu.supporter.interceptor.UserThreadLocal;
import com.santu.edu.supporter.util.UuidUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 12158
 */
@Service
@RequiredArgsConstructor
public class UserAddressServiceImpl implements UserAdressService {

    private final UserAdressDao userAdressDao;

    @Override
    public Boolean addUserAddress(UserAddressAddParam addParam) {
        String addressId = UuidUtils.getUuid(8);
        UserAddressDTO dto = UserAddressDTO.createItem(UserThreadLocal.get(),addressId, addParam);
        userAdressDao.addUserAddress(dto);
        return true;
    }

    @Override
    public Boolean updateUserAddress(UserAddressUpdateParam updateParam) {
        UserAddressDTO dto = UserAddressDTO.createItem(UserThreadLocal.get(),updateParam);
        userAdressDao.updateUserAddress(dto);
        return true;
    }

    @Override
    public Boolean removeUserAddress(String addressId) {
        userAdressDao.removeUserAddress(addressId);
        return true;
    }

    @Override
    public List<UserAddressDTO> getUserAddressList() {
        return userAdressDao.getUserAddressList(UserThreadLocal.get());
    }


}
